﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using LaughingDog.Managers;
using Microsoft.Xna.Framework.Graphics;
using FarseerGames.FarseerPhysics;
using System.Diagnostics;

namespace LaughingDog
{    
    /// <summary>
    /// The main class of the LaughingDog engine, after calling Initialse from your Game class it is ready to use.
    /// </summary>
    public static class Engine
    {
        #region Private Members

        private static Game mGame;
        private static GraphicsDeviceManager mGraphics;        

        #endregion

        #region Public Properties

        /// <summary>
        /// The underlying Game object currently running.
        /// </summary>
        public static Game Game { get { return mGame; } }

        /// <summary>
        /// The GraphicsDeviceManager associated with the current game.
        /// </summary>
        public static GraphicsDeviceManager GraphicsDeviceManager { get { return mGraphics; } }

        #endregion

        #region Public Methods

        /// <summary>
        /// Initialise the LaughingDog engine. After calling this function you are able to use all its features.
        /// </summary>
        /// <param name="game">The Game object that is currently running.</param>
        /// <param name="graphics">The the GraphicsDeviceManager of the current Game.</param>
        public static void Initialise(Game game, GraphicsDeviceManager graphics)
        {
            mGame = game;

            mGraphics = graphics;
            
            mGame.Components.Add(TimeManager.Instance);
            mGame.Components.Add(PhysicsManager.Instance);
            mGame.Components.Add(InputManager.Instance);
            mGame.Components.Add(GameObjectManager.Instance);            
        }

        /// <summary>
        /// Add a Game component to the Engine.
        /// </summary>
        /// <param name="component">The component to add.</param>
        /// <returns>The added component.</returns>
        public static IGameComponent AddComponent(IGameComponent component)
        {
            mGame.Components.Add(component);

            return component;
        }

        /// <summary>
        /// Removes a Game component from the engine.
        /// </summary>
        /// <param name="component">The component to remove.</param>
        public static void RemoveComponent(IGameComponent component)
        {
            mGame.Components.Remove(component);
        }

        /// <summary>
        /// Exits the current game.
        /// </summary>
        public static void Exit()
        {
            mGame.Exit();
        }

        #endregion
    }
}
